package com.example.lib.utils

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.net.Uri

object CopyUtils {
    /**
     * 复制文字到粘贴板
     */
    fun copyString(context: Context, msg: String, label: String = "描述") {
        val nowManager =
            context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
        nowManager.setPrimaryClip(ClipData.newPlainText(label, msg))
    }

    /**
     *复制Uri到粘贴板
     */
    fun copyUri(context: Context, uri: Uri) {
        val nowManager: ClipboardManager =
            context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
        nowManager.setPrimaryClip(ClipData.newRawUri("描述", uri))
    }

}